<?php include $this->getViewFile('/common/Head') ?>
<body class="J_scroll_fixed">
<style>
.col-left{float:left}
.col-auto{overflow:hidden;_zoom:1;_float:left;}
.title-1{border-bottom:1px solid #eee; padding-left:5px}
.f14{font-size: 14px}
.lh28{line-height: 28px}
.blue,.blue a{color:#004499}
.gray4,a.gray4{color:#999;}
.lh22{line-height: 22px}
.lh25{line-height: 25px}
</style>
<div class="wrap J_check_wrap">
  <?php include $this->getViewFile('/common/Nav') ?>

  <!-- 搜索区 -->
  <div class="h_a">查找</div>
  <?php $objForm = $this->beginWidget( 'CActiveForm', array('id' => 'searchForm', 'method' => 'get', 'action' => $this->createUrl('special'))); ?>
    <div class="search_type cc mb10">
      <div class="mb10"> 
      <?php
	  if(RBAC::authenticate('special') && ACTION_NAME == 'special'){
	  ?>
        状态：
        <?php echo $objForm->dropDownList($model, 'status', GoodsBmModel::model()->getStatusTags(), array('empty' => '全部')) ?>
        操作人：
        <?php
		$adminList = array();
		foreach(AdminUser::model()->getUserList() as $rs){
			$adminList[$rs['admin_id']] = $rs['real_name'];
		}
		echo $objForm->dropDownList($model, 'admin_id', $adminList, array('empty' => '全部'))
		?>
      <?php
	  }
	  ?>

        上架时间：
        <input type="text" name="start_time" class="input length_2 J_date" value="<?php echo $start_time?>" placeholder="选择起始时间">
        -
        <input type="text" class="input length_2 J_date" name="end_time" value="<?php echo $end_time?>" placeholder="选择结束时间">
        报名时间：
        <input type="text" name="add_start_time" class="input length_2 J_date" value="<?php echo $add_start_time?>" placeholder="选择起始时间">
        -
        <input type="text" class="input length_2 J_date" name="add_end_time" value="<?php echo $add_end_time?>" placeholder="选择结束时间">
       
       </div>
       <div class="mb10">
        栏目：
        <select class="select_2" name="GoodsBmModel[cat_id]">
          <option value=''>不限栏目</option>
          <?php  echo CategoryModel::model()->htmlCategorySelectOption($model->cat_id); ?>
        </select>

        专场名: <?php echo $objForm->dropDownList($model, 'special_id', GoodsBmModel::getSpecialHtmlList(), array('empty' => '全部')) ?>

        关键字：<?php echo Form::select(array(1=>'商品ID',2=>'商品名称',3=>'商品旺旺'),$type,'name="type"') ?>
        <input type="text" class="input length_2" name="keyword" style="width:200px;" value="<?php echo $keyword?>" placeholder="请输入搜索内容...">
        <button class="btn">搜索</button>
      </div>

    </div>
  <?php $this->endWidget(); ?>
  <div class="mb10"> 共有 ( <b><?php echo $count; ?></b> ) 个宝贝</div>
  <form name="myform" action="<?php echo AdminBase::U("adminSpecial") ?>" method="post" class="J_ajaxForm">
    <div class="table_list">
      <table width="100%" cellspacing="0">
        <thead>
          <tr>
            <td width="50" align="center"><input type="checkbox" class="check_all" data-direction="" data-checklist="">
              全选</td>
            <td width="100" align="center">商品ID</td>
            <td align="center">商品报名信息</td>
            <td width="100" align="center">商品状态</td>
            <td width="200" align="center">管理操作</td>
          </tr>
        </thead>
        <tbody>
          <?php
		  foreach($models as $rs){
		  ?>
            <tr id="gbinfo_<?php echo $rs->goods_id;?>">
              <?php include $this->getViewFile('public_load'); ?>
            </tr>
          <?php
		  }
		  ?>
        </tbody>
      </table>
      <div class="p10">
        <div class="pages"><?php echo $pages;?></div>
      </div>
    </div>

    <!-- 全选 -->
    <div class="btn_wrap">
      <div class="btn_wrap_pd">
        <label class="mr20"><input type="checkbox" class="check_all" data-direction="" data-checklist="">全选</label>
        <select id="operation" name="operation">
        	<option value="0">请选择</option>
        	<option value="1">取消分配</option>
        	<option value="2">分配</option>
        </select>
        <?php 
			$adminList = array();
			foreach(AdminUser::model()->getUserList() as $admin){
				$adminList[$admin['admin_id']] = $admin['real_name'];
			}
			echo Form::select($adminList,$admin_id,'name="admin_id_operation" style="display:none"', '请选择');
         ?>

        <button class="btn" type="submit" data-action="<?php echo AdminBase::U("adminspecial") ?>">确认</button>
      </div>
    </div>



</form>
</div>
<script src="<?php echo $staticUrl; ?>statics/js/common.js"></script>
<script>
$("#operation").change(function(){
	var obj_this = $(this);
	if(obj_this.val() == '0'){
		return;
	}else if(obj_this.val() == '1'){
		$('[name="admin_id_operation"]').hide();
	}else{
		$('[name="admin_id_operation"]').show();
	}
})


//加载信息
function loadGoods(goods_id){
	$.get('<?php echo AdminBase::U("public_load") ?>',{goods_id:goods_id},function(data){
		if(data != ''){
			$("#gbinfo_"+goods_id).html(data);
			changes();
		}
	});
}
//快速编辑
function fastEdit(gid) {
    Wind.use("artDialog", "iframeTools", function () {
		var dialog = art.dialog({
		    title: '快速编辑',
            id: 'fastEdit',
            lock: true,
            fixed: true,
			width:600,
			height:460,
            background: "#CCCCCC",
			padding:'5px 5px',
            opacity: 0
		});
		$.get("<?php echo AdminBase::U("editor") ?>",{ajax:1,goods_id:gid},function(data){
			 if(data == 'no'){
				 alert('该报名信息不存在！');
				 return false;
			 }else if(data == 'status'){
				 alert('该商品已经审核通过，需要修改请到商品管理中修改！');
				 return false;
			 }
			 dialog.content(data);
		});
        /*art.dialog.open('<?php echo AdminBase::U("editor") ?>?ajax=1&goods_id='+gid, {
            title: '快速编辑',
            id: 'fastEdit',
            lock: true,
            fixed: true,
			width:600,
			height:560,
            background: "#CCCCCC",
            opacity: 0
        });*/
    });
}

//绑定事件
function changes(){
	if ($('a.J_ajax_notice').length) {
		Wind.use('artDialog','iframeTools', function () {
			$('.J_ajax_notice').on('click', function (e) {
				e.preventDefault();
				var url = $(this).attr('href');
				var product_id = $(this).data('product_id');
				var dialog = art.dialog({
					title: '信息通知',
					id: 'notice',
					lock: true,
					fixed: true,
					width:600,
					height:70,
					background: "#CCCCCC",
					padding:'5px 5px',
					opacity: 0,
					button:[{
						name:'确定',
						callback:function(){
							var notice = $('form#notice textarea[name="notice"]').val();
							if(notice == ''){
								alert('信息内容不能为空！');
								return false;
							}
							$.getJSON(url,{notice:notice},function(data){
								alert(data.info);
								if(data.status){
									art.dialog.list['notice'].close();
								}
								return true;
							});
							return false;
						},
						focus: true
					}]
				});
				var data = '<div style="overflow:hidden;padding: 5px; ">\
				<form action="<?php echo AdminBase::U("notice") ?>" method="post" id="notice">\
				<div class="table_full">\
				  <table width="100%" class="table_form contentWrap">\
				     <tbody>\
					 <tr>\
					 <th width="80">信息内容</td>\
					 <td><textarea type="text" name="notice" cols="60" rows="3" style="height:50px;width:400px;">亲，您的商品('+product_id+')已经进入初审阶段，请到“报名查询”页面查询商品审核进展（查询后有审核人员旺旺），并联系洽谈。</textarea></td>\
					 </tr>\
					 </tbody>\
				   </table>\
				</div>\
				</form>\
				</div>';
				dialog.content(data);
			});
		});
	}
	//点击进行审核，
	if($('.J_ajax_admin_check').length){
		$('.J_ajax_admin_check input').click(function(){
			var obj = $(this).parent().parent();
			var gid = obj.data('gid');
			Wind.use("artDialog", function (){
				$.get("<?php echo AdminBase::U("admin_check") ?>",{goods_id:gid},function(data){
					if(data.status){
						loadGoods(gid);
					}else{
						art.dialog({
							icon: 'error',
							content: data.info
						});
					}
				},'json');
			});
		});
		$('.J_ajax_admin_check select').change(function(){
			var goods_id = $(this).data('goods_id');
			var admin_id = $(this).val();
			if( goods_id >0 && admin_id>0){
				Wind.use("artDialog", function (){
					$.get("<?php echo AdminBase::U("admin_check") ?>",{goods_id:goods_id,admin_id:admin_id},function(data){
						if(data.status){
							art.dialog.tips('修改成功！', 1.5);
							loadGoods(goods_id);
						}else{
							art.dialog.tips(data.info, 1.5);
						}
					},'json');
				});
			}
		});
	}

}

$(function(){
	changes();
	//只显示本人正在审核的和未审核的报名商品
	if($('input#J_mycheck').length){
		$('input#J_mycheck').click(function(){
			$('#searchForm').submit();
		});
	}


	$(document).on('click','.check_all',function(){
		var obj_this = $(this);
		var data = obj_this[0].checked;
		var obj = $(".check_all");
		var length = obj.length;
		for(var i=0;i<length;i++){
			obj.eq(i)[0].checked = data;
		}

		var obj = $("[name='ids[]']");
		var length = obj.length;
		for(var i=0;i<length;i++){
			obj.eq(i)[0].checked = data;
		}
		
	})


    //查看历史报名的次数，上架的次数及详细信息
    $(".showNumber").click(function() {
        var goods_id = $(this).data('goods_id');
        var obj = $(this);
        if (!goods_id) {
            alert('访问错误');
            return false;
        }
        $.getJSON('<?php echo $this->createUrl("public_opengoodslist") ?>', {
            goods_id: goods_id,
            count: 1
        }, function(data) {
            var shangjia_number = data.status_shangjia;
            var status_baoming = data.status_baoming;
            obj.parent().html("<span style='color:#999;font-size:11px'>报名历史次数：<a data-goods_id='" + goods_id + "' href='javascript:void(0)' class='show_baoming'>" + status_baoming + "</a>，上线历史次数：<a data-goods_id='" + goods_id + "' href='javascript:void(0)' class='show_shangjia'>" + shangjia_number + "</a></span>");
        })
    })
	//历史报名，上架记录查询
    $(document).on("click", ".show_shangjia,.show_baoming", function() {
        var obj = $(this);
        if (parseInt(obj.html()) == 0) {
            //alert('找不到记录');
            return false;
        }
        var status = '';
        var goods_id = obj.data('goods_id');
        if (obj.hasClass('show_baoming')) {
            status = '';
        } else {
            status = 1;
        }
        Wind.use('artDialog', 'iframeTools', function() {
            var dialog = art.dialog.open('<?php echo $this->createUrl("public_opengoodslist") ?>?goods_id=' + goods_id + '&status=' + status, {
                title: '信息列表',
                id: 'notice',
                lock: true,
                fixed: true,
                width: 700,
                height: 500,
                background: "#CCCCCC",
                cancelDisplay: true,
            });
        });
    })	


});
</script>
</body>
</html>